package com.market.inventory.server.controller;

import com.github.pagehelper.PageInfo;
import com.market.common.core.constant.HttpStatus;
import com.market.common.core.domain.Result;
import com.market.common.core.web.page.TableDataInfo;
import com.market.inventory.server.Student;
import com.market.inventory.server.service.StudentService;
import com.market.inventory.server.vo.VoStudent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.market.common.core.utils.PageUtils.startPage;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    StudentService studentService;

    @PostMapping("/list")
    public Result<TableDataInfo> studentlist(@RequestBody VoStudent voStudent){
        startPage();
        List<Student> students=studentService.studentlist(voStudent);
        return getDataTable(students);
    }


    protected Result<TableDataInfo> getDataTable(List<?> list)
    {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        Result<TableDataInfo> returnResult = new Result<>();

        returnResult.setCode(HttpStatus.SUCCESS);
        returnResult.setMsg("查询成功");
        returnResult.setData(rspData);

        return returnResult;
    }
}
